package main

import (
	"fmt"
	"strings"
)

func main() {

	ss := []string{
		"the sky is blue",
		"  hello world  ",
		"a good   example",
		"  Bob    Loves  Alice   ",
		"Alice does not even like bob",
	}

	for _, s := range ss {
		s1 := reverseWords(s)
		fmt.Printf("原句子：%s\n新句子：%s\n", s, s1)
		fmt.Println()
	}
}

func reverseWords1(s string) string {
	temp := make([]string, 0)

	ss := strings.Split(s, " ")

	for i := len(ss) - 1; i >= 0; i-- {
		if ss[i] == "" {
			continue
		}
		temp = append(temp, ss[i])
	}

	return strings.Join(temp, " ")
}

func reverseWords(s string) string {
	f := strings.Fields(s)
	for i := 0; i < len(f)/2; i++ {
		f[i], f[len(f)-i-1] = f[len(f)-i-1], f[i]
	}
	return strings.Join(f, " ")
}
